package com.heima.behavior.listen;

import com.alibaba.fastjson.JSON;
import com.heima.behavior.service.ApFollowBehaviorService;
import com.heima.common.constans.message.FollowBehaviorConstants;
import com.heima.model.behavior.dtos.FollowBehaviorDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;


@Component
@Slf4j
public class FollowBehaviorListener {
    @Autowired
    private ApFollowBehaviorService apFollowBehaviorService;
    @KafkaListener(topics = FollowBehaviorConstants.FOLLOW_BEHAVIOR_TOPIC)
    public void receiverMessage(String followMsgJson){
        //接收关注行为数据，保存
//        log.info("关注行为监听触发，接收到关注消息==>{}",followMsgJson);
        if(StringUtils.isNotBlank(followMsgJson)){
            FollowBehaviorDto dto = JSON.parseObject(followMsgJson, FollowBehaviorDto.class);
            apFollowBehaviorService.saveFollowBehavior(dto);
        }
    }
}